package com.lizhi.yun.core.training;/**
 * @program: hbsf_yun
 * @name RszGameTrainingHandler
 * @description: 训练记录
 * @author: lizhi
 * @create: 2021-11-03 14:17
 */

import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.mybatis.interceptor.PageBounds;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.rsz.dao.RszPatientDao;
import com.lizhi.yun.db.rsz.dao.RszPrescriptionDao;
import com.lizhi.yun.db.rsz.dao.RszTrainRecordDao;
import com.lizhi.yun.db.rsz.entity.RszPatientEntity;
import com.lizhi.yun.db.rsz.entity.RszPrescriptionEntity;
import com.lizhi.yun.db.rsz.entity.RszTrainRecordEntity;
import com.lizhi.yun.deploy.NewBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *@program: hbsf_yun
 *@name RszGameTrainingHandler
 *@description: 训练记录
 *@author: lizhi
 *@create: 2021-11-03 14:17
 */
@Slf4j
@Service
public class RszTrainingHandler extends NewBaseHandler {

    @Resource
    private RszTrainRecordDao rszTrainRecordDao;

    @Resource
    private RszPatientDao rszPatientDao;

    @Resource
    private RszPrescriptionDao rszPrescriptionDao;

    /**
     *功能描述 根据训练记录id和患者id模糊查询
     * @author lizhi
     * @date 2021/11/3
     * @param json:
     * @return com.lizhi.common.yun.entity.ListResponseResult
     */
    public ListResponseResult doMain(String json){
        Map<String, Object> map = SamJsonUtil.toMap(json);
        PageBounds pageBounds = getPageBounds(map);
        List<RszTrainRecordEntity> rszTrainRecordEntities = rszTrainRecordDao.selectByMap(map, pageBounds);
        for (RszTrainRecordEntity rszTrainRecordEntity : rszTrainRecordEntities){
            RszPatientEntity rszPatientEntity = rszPatientDao.selectById(rszTrainRecordEntity.ptId, rszTrainRecordEntity.hospitalId, rszTrainRecordEntity.hospitalSystemId);
            rszTrainRecordEntity.rszPatientEntity = rszPatientEntity;
            RszPrescriptionEntity rszPrescriptionEntity = rszPrescriptionDao.selectById(rszTrainRecordEntity.preId, rszTrainRecordEntity.hospitalId, rszTrainRecordEntity.hospitalSystemId);
            rszTrainRecordEntity.rszPrescriptionEntity = rszPrescriptionEntity;
        }
        return getListResult(pageBounds.getCountRows(), rszTrainRecordEntities, map);
    }
}
